var roleManage = function() {
	var defaultContent="<button type=\"button\" class=\"btn blue btn_edit_role\">修改</button><button type=\"button\" class=\"btn red btn_del_role\">删除</button>";

    var _init = function() {
        var table = $('#advertisement_talbe');
        table.dataTable({
            "processing": true,
            destroy:true, 
            // 开启服务器模式
            serverSide: true,
            "ajax": {
            	url:"/a/wxconf/applet/advertisements",
            },
            "autoWidth": false,
            "columns": [{
                    "width": "20%",
                    "data": "imgUrl",
                    "render": function(data, type, row, meta) {
                         return "<img class='img-responsive center-block' src='"+data+"' alt='' />"
                   }
                },{
                    "width": "20%",
                    "data": "linkType",
                    "render": function(data, type, row, meta) {
                    	 return mdTool.getLikeTpe(data);
		            }
                },
                {
                    "width": "10%",
                    "data": "orderNo"
                },
                {
                    "width": "25%",
                    "data": "null",
                    "defaultContent": defaultContent
                }
            ],
            "language": {
            	url: '/assets/pages/Chinese.json'
            },
            "pageLength": 5,
            "order": [
                [2, "asc"]
            ],
            "columnDefs": [{
                "orderable": false,
                "targets": [0, 3]
            }],
            "dom": "<'row'<'.col-md-6 col-sm-12'><'col-md-6 col-sm-12'>r>" +
                "<t>" +
                "<'table_b relative'<'col-md-5'i><'col-md-7'>p>",
            "fnInitComplete": function() {

            }
        });
        
        
        // 新增或保存
        table.on('click', '.btn_save_role', function(event) {
            var oData_arr = table.DataTable().rows($(this).parents("tr"))
                .data(); // 操作行对象
            var imgUrl= $('#advertisement [name="img_qiniu_url"]')[0].src; 
            var displayName= $('#advertisement [name="displayName"]').val(); 
        	var orderNo= $('#advertisement [name="orderNo"]').val(); 
        	var linkType= $('#advertisement [name="linkType"]').val(); 
        	var linkId= $('#advertisement [name="linkId"]').val(); 

        	var _id= $('[name="ids"]').val(); 
          	var frameId=$("#frameIds").val();

        	
//        	var msgId=" .help-block";
        	if (!mdTool.validate(imgUrl, 'require')) {
        		mdTool.showMessageForHelpBlock('请上传图片');
        		return;
        	}
        	if (!mdTool.validate(linkType, 'require')) {
        		mdTool.showMessageForHelpBlock('请选择链接类型');
        		return;
        	}
        	 if(!isRequireLinkId(linkType)){
        		 linkId="";
        	 }else if (!mdTool.validate(linkId, 'require')) {
        		mdTool.showMessageForHelpBlock('请选择弹框信息');
        		return;
        	}
        	if (!mdTool.validate(orderNo, 'num')) {
        		mdTool.showMessageForHelpBlock('请输入正确的排序');
        		return;
        	}else {
            	var param={"id":_id,"imgUrl":imgUrl,"orderNo":orderNo,"linkType":linkType,"linkId":linkId,"displayName":displayName,"frameId":frameId};

        		var _type = _id == null||_id == '' ? "put" : "post";

        		$.ajax({
        			url : '/a/wxconf/applet/advertisement',
        			type : _type,
        			dataType : 'json',
        			contentType:"application/json; charset=utf-8",
        			data : JSON.stringify(param),
        		}).done(function(data) {
        			if (data.status === '1') {
        				// 正确
        				table.DataTable().ajax.reload();
        				$("#advertisement_btn").attr("disabled",false);
//        				window.location.reload();
        				$(' .help-block').html('');

        			} else if (data.status === '2') {
//        				错误
        				mdTool.showMessageForHelpBlock(data.message);
        			}
        		});
        	}
        });
        
        // 修改
        table.on('click', '.btn_edit_role', function(event) {
        	$(this).attr("disabled","disabled");
        	$(this).parents("tr").siblings("tr").find(".btn_edit_role").attr("disabled","disabled");
        	$(this).parents(".site").find(".btn_add_class").attr("disabled","disabled");
            var oData_arr = table.DataTable().rows($(this).parents("tr"))
                .data(); // 操作行对象
            var _id = oData_arr[0].id;
            var imgUrl = oData_arr[0].imgUrl;
            var orderNo = oData_arr[0].orderNo;
            var linkType = oData_arr[0].linkType;
            var linkId = oData_arr[0].linkId;


            $("#advertisement_talbe tbody:last").append(advertisementTemplate);
      	    getTokenMessage();
            $('#btn-uploader [ type="button"]').css('background',"url("+imgUrl+")"); 
            $('#btn-uploader [ type="button"]').css('background-size',"100%"); 
            $('#advertisement [name="img_qiniu_url"]').attr('src',imgUrl); 
	        $('#advertisement [name="orderNo"]').val(orderNo); 
	       	$('#advertisement [name="linkId"]').val(linkId); 
	       	$('#advertisement [name="linkType"]').val(linkType); 

	        $('[name="ids"]').val(_id); 
     	    
        });
        
        
        // 删除
        table.on('click', '.btn_del_role', function(event) {
    	   var oData_arr = table.DataTable().rows($(this).parents("tr")).data(); 
           var _id = oData_arr[0].id;
            deleteComponent(_id,table);
        });
        
      
        
        /*-------------------图标页面---------------------------*/
        
        var iconArea_talbe = $('#iconArea_talbe');
        iconArea_talbe.dataTable({
            "processing": true,
            // 开启服务器模式
            serverSide: true,
            destroy:true, 
            "ajax": {
            	url:"/a/wxconf/applet/advertisements",

            },
            "autoWidth": false,
            "columns": [{
                    "width": "10%",
                    "data": "imgUrl",
                    "render": function(data, type, row, meta) {
                        return "<img class='img-responsive center-block' src='"+data+"' alt='' />"
                  }
                },{
                    "width": "20%",
                    "data": "displayName"
                },{
                    "width": "20%",
                    "data": "linkType",
                    "render": function(data, type, row, meta) {
                      return mdTool.getLikeTpe(data);
		            }
                },
                {
                    "width": "10%",
                    "data": "orderNo"
                },
                {
                    "width": "25%",
                    "data": "null",
                    "defaultContent": defaultContent
                }
            ],
            "language": {
            	url: '/assets/pages/Chinese.json'
            },
            "pageLength": 5,
            "order": [
                [3, "asc"]
            ],
            "columnDefs": [{
                "orderable": false,
                "targets": [0, 4]
            }],
            "dom": "<'row'<'.col-md-6 col-sm-12'><'col-md-6 col-sm-12'>r>" +
                "<t>" +
                "<'table_b relative'<'col-md-5'i><'col-md-7'>p>",
            "fnInitComplete": function() {
            	
            }
        });
        
        
        // 新增
        iconArea_talbe.on('click', '.btn_save_role', function(event) {
            var oData_arr = iconArea_talbe.DataTable().rows($(this).parents("tr"))
                .data(); // 操作行对象
            
          
        	var linkId= $('#iconAreaList [name="linkId"]').val(); 

          	var frameId=$("#frameIds").val();
            
            var imgUrl= $('#iconAreaList [name="img_qiniu_url"]')[0].src; 
        	var orderNo= $('#iconAreaList [name="orderNo"]').val(); 
        	var linkType= $('#iconAreaList [name="linkType"]').val(); 
        	var displayName= $('#iconAreaList [name="displayName"]').val(); 

        	var _id= $('[name="ids"]').val(); 
        	
        	var msgId="iconAreaList .help-block";
        	if (!mdTool.validate(imgUrl, 'require')) {
        		mdTool.showMessageForHelpBlock('请上传图片');
        		return;
        	}if (!mdTool.validate(displayName, 'require')) {
        		mdTool.showMessageForHelpBlock('请输入按钮名称');
        		return;
        	}/*if (!mdTool.validate(linkId, 'require')) {
        		mdTool.showMessageForHelpBlock('请选择链接类型');
        		return;
        	}*/
        	if (!mdTool.validate(linkType, 'require')) {
        		mdTool.showMessageForHelpBlock('请选择链接类型');
        		return;
        	}	
        	 if(!isRequireLinkId(linkType)){
        		 linkId="";
        	 }else if (!mdTool.validate(linkId, 'require')) {
	     		mdTool.showMessageForHelpBlock('请选择弹框信息');
	     		return;
	     	}
        	if (!mdTool.validate(orderNo, 'num')) {
        		mdTool.showMessageForHelpBlock('请输入正确的排序');
        		return;
        	}else {
            	var param={"id":_id,"imgUrl":imgUrl,"orderNo":orderNo,"linkType":linkType,"linkId":linkId,"displayName":displayName,"frameId":frameId};

        		var _type = _id == null||_id == '' ? "put" : "post";

        		$.ajax({
        			url : '/a/wxconf/applet/iconArea',
        			type : _type,
        			dataType : 'json',
        			contentType:"application/json; charset=utf-8",
        			data : JSON.stringify(param),
        		}).done(function(data) {
        			if (data.status === '1') {
        				// 正确
        				iconArea_talbe.DataTable().ajax.reload();
        				$("#iconArea_btn").attr("disabled",false);
        				//window.location.reload();
        				
        				$('#'+msgId).html(''); 
        				$(' .help-block').html('');



        			} else if (data.status === '2') {
//        				错误
        				mdTool.showMessageForHelpBlock(data.message);
        			}
        		});
        	}
        });
        
        
        
        // 修改
        iconArea_talbe.on('click', '.btn_edit_role', function(event) {
        	$(this).attr("disabled","disabled");
        	$(this).parents("tr").siblings("tr").find(".btn_edit_role").attr("disabled","disabled");
//        	$(this).parents(".dataTables_wrapper").next(".btn").attr("disabled","disabled");
        	$(this).parents(".site").find(".btn_add_class").attr("disabled","disabled");

            var oData_arr = iconArea_talbe.DataTable().rows($(this).parents("tr"))
                .data(); // 操作行对象
            var _id = oData_arr[0].id;
            var imgUrl = oData_arr[0].imgUrl;
            var orderNo = oData_arr[0].orderNo;
            var linkType = oData_arr[0].linkType;
            var displayName = oData_arr[0].displayName;
            var linkId = oData_arr[0].linkId;

            $("#iconArea_talbe tbody:last").append(iconTemplate);
    	    getTokenMessage();
            $('#iconAreaList [name="img_qiniu_url"]').attr('src',imgUrl); 
            $('#btn-uploader [ type="button"]').css('background',"url("+imgUrl+")"); 
            $('#btn-uploader [ type="button"]').css('background-size',"100%"); 
	        $('#iconAreaList [name="orderNo"]').val(orderNo); 
	       	$('#iconAreaList [name="linkType"]').val(linkType); 
	       	$('#iconAreaList [name="displayName"]').val(displayName); 
	       	$('#iconAreaList [name="linkId"]').val(linkId); 


	        $('[name="ids"]').val(_id); 
	        
        });
        
        
        
        // 删除
        iconArea_talbe.on('click', '.btn_del_role', function(event) { 
        	 var oData_arr = iconArea_talbe.DataTable().rows($(this).parents("tr")).data(); 
             var _id = oData_arr[0].id;
              deleteComponent(_id,iconArea_talbe);
        });
     
        
        
        
        /*-------------------商品页面---------------------------*/

        var commodity_table = $('#commodity_table');
        commodity_table.dataTable({
            "processing": true,
            // 开启服务器模式
            serverSide: true,
            destroy:true, 
            "ajax": {
            	url:"/a/wxconf/applet/advertisements",
            },
            "autoWidth": false,
            "columns": [{
                    "width": "50%",
                    "data": "displayName"
                },
                {
                    "width": "25%",
                    "data": "orderNo"
                },
                {
                    "width": "25%",
                    "data": "null",
                    "defaultContent": defaultContent
                }
            ],
            "language": {
            	url: '/assets/pages/Chinese.json'
            },
            "pageLength": 5,
            "order": [
                [1, "asc"]
            ],
            "columnDefs": [{
                "orderable": false,
                "targets": [0, 2]
            }],
            "dom": "<'row'<'.col-md-6 col-sm-12'><'col-md-6 col-sm-12'>r>" +
                "<t>" +
                "<'table_b relative'<'col-md-5'i><'col-md-7'>p>",
            "fnInitComplete": function() {
            }
        });
        
        /*******拼团*****/
        var groupbuy_table = $('#groupbuy_table');
        groupbuy_table.dataTable({
            "processing": true,
            // 开启服务器模式
            serverSide: true,
            destroy:true, 
            "ajax": {
            	url:"/a/wxconf/applet/advertisements",
            },
            "autoWidth": false,
            "columns": [{
                    "width": "50%",
                    "data": "displayName"
                },
                {
                    "width": "25%",
                    "data": "orderNo"
                },
                {
                    "width": "25%",
                    "data": "null",
                    "defaultContent": defaultContent
                }
            ],
            "language": {
            	url: '/assets/pages/Chinese.json'
            },
            "pageLength": 5,
            "order": [
                [1, "asc"]
            ],
            "columnDefs": [{
                "orderable": false,
                "targets": [0, 2]
            }],
            "dom": "<'row'<'.col-md-6 col-sm-12'><'col-md-6 col-sm-12'>r>" +
                "<t>" +
                "<'table_b relative'<'col-md-5'i><'col-md-7'>p>",
            "fnInitComplete": function() {
            }
        });
        
        
        
        // 新增
        commodity_table.on('click', '.btn_save_role', function(event) {
            var oData_arr = commodity_table.DataTable().rows($(this).parents("tr"))
                .data(); // 操作行对象
        	var orderNo= $('#commoditylist [name="orderNo"]').val(); 
        	//var linkType= $('#commoditylist [name="linkType"]').val(); 
        	var linkId= $('#commoditylist [name="linkId"]').val(); 
        	var displayName= $('#commoditylist [name="displayName"]').val(); 

        	var _id= $('[name="ids"]').val(); 
          	var frameId=$("#frameIds").val();

        	var param={"id":_id,"orderNo":orderNo,"linkId":linkId,"frameId":frameId,"displayName":displayName};
        	var msgId="commoditylist .help-block";
        	if (!mdTool.validate(linkId, 'require')) {
        		mdTool.showMessageForHelpBlock('请选择商品');
        		return;
        	}
        	if (!mdTool.validate(orderNo, 'num')) {
        		mdTool.showMessageForHelpBlock('请输入正确的排序');
        		return;
        	}else {
        		var _type = _id == null||_id == '' ? "put" : "post";

        		$.ajax({
        			url : '/a/wxconf/applet/commodity',
        			type : _type,
        			dataType : 'json',
        			contentType:"application/json; charset=utf-8",
        			data : JSON.stringify(param),
        		}).done(function(data) {
        			if (data.status === '1') {
        				// 正确
        				commodity_table.DataTable().ajax.reload();
        				$("#commodity_btn").attr("disabled",false);
        				//window.location.reload();
        				$('#'+msgId).html(''); 

        				$(' .help-block').html('');

        			} else if (data.status === '2') {
//        				错误
        				mdTool.showMessageForHelpBlock(data.message);
        			}
        		});
        	}
        });
        
        // 修改
        commodity_table.on('click', '.btn_edit_role', function(event) {
        	$(this).attr("disabled","disabled");
        	$(this).parents("tr").siblings("tr").find(".btn_edit_role").attr("disabled","disabled");
//        	$(this).parents(".dataTables_wrapper").next(".btn").attr("disabled","disabled");
        	$(this).parents(".site").find(".btn_add_class").attr("disabled","disabled");

            var oData_arr = commodity_table.DataTable().rows($(this).parents("tr"))
                .data(); // 操作行对象
            var _id = oData_arr[0].id;
            var imgUrl = oData_arr[0].imgUrl;
            var orderNo = oData_arr[0].orderNo;
           // var linkType = oData_arr[0].linkType;
            var displayName = oData_arr[0].displayName;
            var linkId = oData_arr[0].linkId;

            
          //  commodity_btn_add();
            $("#commodity_table tbody:last").append(productTemplate);
         
	        $('#commoditylist [name="orderNo"]').val(orderNo); 
	       	//$('#commoditylist [name="linkType"]').val(linkType); 
	       	$('#commoditylist [name="displayName"]').val(displayName); 
        	$(this).parent().parent().parent().find("[name='displayName']").html(displayName);

	       	$('#commoditylist [name="linkId"]').val(linkId); 

	        $('[name="ids"]').val(_id); 
	        
     	    
        });
        
        
        // 删除
        commodity_table.on('click', '.btn_del_role', function(event) {
        	 var oData_arr = commodity_table.DataTable().rows($(this).parents("tr")).data(); 
             var _id = oData_arr[0].id;
              deleteComponent(_id,commodity_table);
        });
     
        
        $('#groupbuy_btn').click(function(event){
        	 $("#groupbuy_table tbody:last").append(groupTemplate);
        	$(this).attr("disabled","disabled");
        	$(".btn-groupbuy-site table .btn_edit_role").attr("disabled","disabled");
      	  $('[name="ids"]').val(""); 

      	  });
        
        
      /* 拼团  */
        groupbuy_table.on('click', '.btn_save_role', function(event) {
            var oData_arr = groupbuy_table.DataTable().rows($(this).parents("tr"))
                .data(); // 操作行对象
        	var orderNo= $('#group_buy [name="orderNo"]').val(); 
        	//var linkType= $('#commoditylist [name="linkType"]').val(); 
        	var linkId= $('#group_buy [name="linkId"]').val(); 
        	//var displayName= $('#group_buy [name="displayName"]').html(); 
        	var displayName=$(this).parent().parent().find("[name='displayName']").html();

        	var _id= $('[name="ids"]').val(); 
          	var frameId=$("#frameIds").val();

        	var param={"id":_id,"orderNo":orderNo,"linkId":linkId,"frameId":frameId,"displayName":displayName};
        	var msgId="group_buy .help-block";
        	if (!mdTool.validate(linkId, 'require')) {
        		mdTool.showMessageForHelpBlock('请选择拼团商品');
        		return;
        	}
        	if (!mdTool.validate(orderNo, 'num')) {
        		mdTool.showMessageForHelpBlock('请输入正确的排序');
        		return;
        	}else {
        		var _type = _id == null||_id == '' ? "put" : "post";

        		$.ajax({
        			url : '/a/wxconf/applet/group',
        			type : _type,
        			dataType : 'json',
        			contentType:"application/json; charset=utf-8",
        			data : JSON.stringify(param),
        		}).done(function(data) {
        			if (data.status === '1') {
        				// 正确
        				groupbuy_table.DataTable().ajax.reload();
        				$("#groupbuy_btn").attr("disabled",false);
        				//window.location.reload();
        				$('.help-block').html(''); 

        			} else if (data.status === '2') {
//        				错误
        				mdTool.showMessageForHelpBlock(data.message);
        			}
        		});
        	}
        });
     
        // 修改
        groupbuy_table.on('click', '.btn_edit_role', function(event) {
        	$(this).attr("disabled","disabled");
        	$(this).parents("tr").siblings("tr").find(".btn_edit_role").attr("disabled","disabled");
//        	$(this).parents(".dataTables_wrapper").next(".btn").attr("disabled","disabled");
        	$(this).parents(".site").find(".btn_add_class").attr("disabled","disabled");

            var oData_arr = groupbuy_table.DataTable().rows($(this).parents("tr"))
                .data(); // 操作行对象
            var _id = oData_arr[0].id;
            var imgUrl = oData_arr[0].imgUrl;
            var orderNo = oData_arr[0].orderNo;
           // var linkType = oData_arr[0].linkType;
            var displayName = oData_arr[0].displayName;
            var linkId = oData_arr[0].linkId;

            
            $("#groupbuy_table tbody:last").append(groupTemplate);
        	$(this).parent().parent().find("[name='displayName']").html(displayName);

	        $('#group_buy [name="orderNo"]').val(orderNo); 
	       	$('#group_buy [name="displayName"]').val(displayName); 
	       	$('#group_buy [name="linkId"]').val(linkId); 

	        $('[name="ids"]').val(_id); 
	        
     	    
        });
        
        
        // 删除
        groupbuy_table.on('click', '.btn_del_role', function(event) {
        	 var oData_arr = groupbuy_table.DataTable().rows($(this).parents("tr")).data(); 
             var _id = oData_arr[0].id;
              deleteComponent(_id,groupbuy_table);
        });
     
        
        

        var article_ban_table = $('#article_ban_table');
        article_ban_table.dataTable({
            "processing": true,
            // 开启服务器模式
            serverSide: true,
            destroy:true, 
            "ajax": {
            	url:"/a/wxconf/applet/advertisements",
            },
            "autoWidth": false,
            "columns": [{
                "width": "20%",
                "data": "displayName",
               /* "render": function(data, type, row, meta) {
                	 return mdTool.getLikeTpe(data);
	            }*/
            },
                {
                    "width": "25%",
                    "data": "orderNo"
                },
                {
                    "width": "25%",
                    "data": "null",
                    "defaultContent": defaultContent
                }
            ],
            "language": {
            	url: '/assets/pages/Chinese.json'
            },
            "pageLength": 5,
            "order": [
                [1, "asc"]
            ],
            "columnDefs": [{
                "orderable": false,
                "targets": [0, 2]
            }],
            "dom": "<'row'<'.col-md-6 col-sm-12'><'col-md-6 col-sm-12'>r>" +
                "<t>" +
                "<'table_b relative'<'col-md-5'i><'col-md-7'>p>",
            "fnInitComplete": function() {
            }
        });
        
        // 新增
        article_ban_table.on('click', '.btn_save_role', function(event) {
            var oData_arr = article_ban_table.DataTable().rows($(this).parents("tr"))
                .data(); // 操作行对象
        	var orderNo= $(this).parent().parent().find("input[name='orderNo']").val(); 
        	var linkId= $(this).parent().parent().find("input[name='linkId']").val(); 
        	var displayName= $(this).parent().parent().find("[name='displayName']").html(); 
        	var _id= $('[name="ids"]').val(); 
          	var frameId=$("#frameIds").val();

        	var param={"id":_id,"orderNo":orderNo,"linkId":linkId,"frameId":frameId,"displayName":displayName,"linkType":'7'};
        	if (!mdTool.validate(linkId, 'require')) {
        		mdTool.showMessageForHelpBlock('请选择文章');
        		return;
        	}
        	if (!mdTool.validate(orderNo, 'num')) {
        		mdTool.showMessageForHelpBlock('请输入正确的排序');
        		return;
        	}else {
        		var _type = _id == null||_id == '' ? "post" : "put";

        		$.ajax({
        			url : '/a/wxconf/applet/applet',
        			type : _type,
        			dataType : 'json',
        			contentType:"application/json; charset=utf-8",
        			data : JSON.stringify(param),
        		}).done(function(data) {
        			if (data.status === '1') {
        				// 正确
        				article_ban_table.DataTable().ajax.reload();
        				$("#article_btn").attr("disabled",false);
        				$(' .help-block').html('');
        			} else if (data.status === '2') {
//        				错误
        				mdTool.showMessageForHelpBlock(data.message);
        			}
        		});
        	}
        });
        
        // 修改
        article_ban_table.on('click', '.btn_edit_role', function(event) {
        	$(this).attr("disabled","disabled");
        	$(this).parents("tr").siblings("tr").find(".btn_edit_role").attr("disabled","disabled");
        	$(this).parents(".site").find(".btn_add_class").attr("disabled","disabled");

            var oData_arr = article_ban_table.DataTable().rows($(this).parents("tr"))
                .data(); // 操作行对象
            var _id = oData_arr[0].id;
            var imgUrl = oData_arr[0].imgUrl;
            var orderNo = oData_arr[0].orderNo;
           // var linkType = oData_arr[0].linkType;
            var displayName = oData_arr[0].displayName;
            var linkId = oData_arr[0].linkId;

            
          //  commodity_btn_add();
            $("#article_ban_table tbody:last").append(articleTemplate);
            $("#article_ban_table [name='displayName']").html(displayName);
            $(this).parent().parent().parent().find("input[name='orderNo']").val(orderNo);
            $(this).parent().parent().parent().find("input[name='displayName']").val(displayName);
            $(this).parent().parent().parent().find("input[name='linkId']").val(linkId);
            $('[name="ids"]').val(_id); 
        });
        
        
        // 删除
        article_ban_table.on('click', '.btn_del_role', function(event) {
        	 var oData_arr = article_ban_table.DataTable().rows($(this).parents("tr")).data(); 
             var _id = oData_arr[0].id;
              deleteComponent(_id,commodity_table);
        });
        
        
        var pic_ban_table = $('#pic_ban_table');
        pic_ban_table.dataTable({
            "processing": true,
            // 开启服务器模式
            serverSide: true,
            destroy:true, 
            "ajax": {
            	url:"/a/wxconf/applet/advertisements",
            },
            "autoWidth": false,
            "columns": [{
                "width": "17%",
                "data": "imgUrl",
                "render": function(data, type, row, meta) {
                     return "<img class='img-responsive center-block' src='"+data+"' alt='' />"
               }
            },{
                "width": "20%",
                "data": "linkType",
                "render": function(data, type, row, meta) {
                	 return mdTool.getLikeTpe(data);
	            }
            },
                {
                    "width": "25%",
                    "data": "orderNo"
                },
                {
                    "width": "25%",
                    "data": "null",
                    "defaultContent": defaultContent
                }
            ],
            "language": {
            	url: '/assets/pages/Chinese.json'
            },
            "pageLength": 5,
            "order": [
                [2, "asc"]
            ],
            "columnDefs": [{
                "orderable": false,
                "targets": [0, 3]
            }],
            "dom": "<'row'<'.col-md-6 col-sm-12'><'col-md-6 col-sm-12'>r>" +
                "<t>" +
                "<'table_b relative'<'col-md-5'i><'col-md-7'>p>",
            "fnInitComplete": function() {
            }
        });
        
        // 新增
        pic_ban_table.on('click', '.btn_save_role', function(event) {
            var oData_arr = pic_ban_table.DataTable().rows($(this).parents("tr"))
                .data(); // 操作行对象
        	var orderNo= $(this).parent().parent().find("input[name='orderNo']").val(); 
        	var linkId= $(this).parent().parent().find("input[name='linkId']").val(); 
        	var linkType= $(this).parent().parent().find("[name='linkType']").val(); 
        	var imgUrl= $(this).parent().parent().find("[name='img_qiniu_url']")[0].src; 
        	//var displayName= $(this).parent().parent().find("input[name='displayName']").val(); 
        	var _id= $('[name="ids"]').val(); 
          	var frameId=$("#frameIds").val();

        	var param={"id":_id,"orderNo":orderNo,"linkId":linkId,"frameId":frameId,"displayName":'自适应图片',"linkType":linkType,"imgUrl":imgUrl};
        	if (!mdTool.validate(imgUrl, 'require')) {
        		mdTool.showMessageForHelpBlock('请上传图片');
        		return;
        	}
        	if (!mdTool.validate(linkType, 'require')) {
        		mdTool.showMessageForHelpBlock('请选择链接类型');
        		return;
        	}	
	       	 if(!isRequireLinkId(linkType)){
	    		 linkId="";
	    	 }else if (!mdTool.validate(linkId, 'require')) {
	    		mdTool.showMessageForHelpBlock('请选择弹框信息');
	    		return;
	    	}
        
        	if (!mdTool.validate(orderNo, 'num')) {
        		mdTool.showMessageForHelpBlock('请输入正确的排序');
        		return;
        	}
        	
        	else {
        		var _type = _id == null||_id == '' ? "post" : "put";

        		$.ajax({
        			url : '/a/wxconf/applet/applet',
        			type : _type,
        			dataType : 'json',
        			contentType:"application/json; charset=utf-8",
        			data : JSON.stringify(param),
        		}).done(function(data) {
        			if (data.status === '1') {
        				// 正确
        				pic_ban_table.DataTable().ajax.reload();
        				$("#pic_btn").attr("disabled",false);
        				$(' .help-block').html('');
        			} else if (data.status === '2') {
//        				错误
        				mdTool.showMessageForHelpBlock(data.message);
        			}
        		});
        	}
        });
        
        // 修改
        pic_ban_table.on('click', '.btn_edit_role', function(event) {
        	$(this).attr("disabled","disabled");
        	$(this).parents("tr").siblings("tr").find(".btn_edit_role").attr("disabled","disabled");
        	$(this).parents(".site").find(".btn_add_class").attr("disabled","disabled");

            var oData_arr = pic_ban_table.DataTable().rows($(this).parents("tr"))
                .data(); // 操作行对象
            var _id = oData_arr[0].id;
            var imgUrl = oData_arr[0].imgUrl;
            var orderNo = oData_arr[0].orderNo;
            var linkType = oData_arr[0].linkType;
            var displayName = oData_arr[0].displayName;
            var linkId = oData_arr[0].linkId;

            
            $("#pic_ban_table tbody:last").append(picTemplate);
            // getTokenMessage();
            getTokenMessage1("pickfiles10");
            $("#pic_ban_table [name='displayName']").html(displayName);
            $(this).parent().parent().parent().find("[name='linkType']").val(linkType);

            $(this).parent().parent().parent().find("input[name='orderNo']").val(orderNo);
            $(this).parent().parent().parent().find("input[name='displayName']").val(displayName);
            $(this).parent().parent().parent().find("input[name='linkId']").val(linkId);
            $(this).parent().parent().parent().find("[name='img_qiniu_url']").attr('src',imgUrl);

            $('[name="ids"]').val(_id); 
        });
        
        
        // 删除
        pic_ban_table.on('click', '.btn_del_role', function(event) {
        	 var oData_arr = pic_ban_table.DataTable().rows($(this).parents("tr")).data(); 
             var _id = oData_arr[0].id;
              deleteComponent(_id,commodity_table);
        });
        
        
        
        // 模块删除
       	$("#applet").on('click','.btn_del_module',function(){
       		console.log("删除");
       		var frameId=$(this).prev().prev().val();
       		if(!frameId){
       			frameId=$(this).prev().val();
       		}
       		if(!frameId){
       			frameId=$(this).prev().prev().prev().val();
       		}
       	    var param={"frameId":frameId};
       	 	url="/a/wxconf/applet/wxFrameConf";
            bootbox.dialog({
                message: "确定要删除",
                title: "提示",
                buttons: {
                    cancel: {
                        label: "取消",
                        className: "btn dark btn-outline"
                    },
                    success: {
                        label: "确定",
                        className: "btn green",
                        callback: function() {
                            var _data = JSON.stringify({ id: frameId });
                            request_role_del(_data, function(res) {
                                // 正确
//                            	$(this).parent().parent().remove();
                            	window.location.reload();

//                            	iconArea_talbe.DataTable().ajax.reload();
                            }, function(err) {
                                //	错误
                                alert(err);
                            })
                        }
                    }
                }
            });
       		
       	});
       	
       	// 模块取消
	   	$("#applet").on('click','.btn_cancle_role',function(){
	   		console.log("取消");
	   		$(this).parents("table").find(".btn_edit_role").attr("disabled",false);
	   		$(this).parents(".site").find(".btn_add_class").attr("disabled",false);
	   		$(this).parent().parent().remove();
	   		return false;
	   	});
       	
       	
        // 关闭弹框
        $(".modal").on('hidden.bs.modal', function(e) {
            $('.modal .alert').css('display', 'none'); // 隐藏提示头
            $('.modal .form-group').removeClass('has-error'); //清除错误信息
            $('.modal input[type="text"]').val(''); // 清空 input
            $('.modal input[type="checkbox"]').prop('checked', false); // 清空 input
        });
        
       
        
     
       /*----------添加行代码----------*/
        var i = 0;
        $('#advertisement_btn').click(function(event){
        	$(this).attr("disabled","disabled");
        	$(".ban-site table .btn_edit_role").attr("disabled","disabled");
        	  $("#advertisement_talbe tbody:last").append(advertisementTemplate);
        	    getTokenMessage();
        	  $('[name="ids"]').val(""); 
        });
        
        
        $('#iconArea_btn').click(function(event){
        	  $("#iconArea_talbe tbody:last").append(iconTemplate);
      	    getTokenMessage();
        	$(this).attr("disabled","disabled");
        	$(".btn-nav-site table .btn_edit_role").attr("disabled","disabled");
        	  $('[name="ids"]').val(""); 


     	  });
        
       
        $('#commodity_btn').click(function(event){
        	//commodity_btn_add();
            $("#commodity_table tbody:last").append(productTemplate);

        	$(this).attr("disabled","disabled");
        	$(".btn-pro-site table .btn_edit_role").attr("disabled","disabled");
      	  $('[name="ids"]').val(""); 

      	  });
        
        
        $('#article_btn').click(function(event){
        	//commodity_btn_add();
            $("#article_ban_table tbody:last").append(articleTemplate);
        	$(this).attr("disabled","disabled");
        	$(".btn-article-site table .btn_edit_role").attr("disabled","disabled");
      	  $('[name="ids"]').val(""); 

      	  });
        
        $('#pic_btn').click(function(event){
        	//commodity_btn_add();
        	$("#pic_ban_table tbody:last").append(picTemplate);
            getTokenMessage1("pickfiles10");
        	$(this).attr("disabled","disabled");
        	$(".btn-pic-site table .btn_edit_role").attr("disabled","disabled");
      	  $('[name="ids"]').val(""); 

      	  });
        
        
        
    }

    return {
        init: function() {
            _init();
        }

    };

}();



function deleteComponent(_id,table) {
	url="/a/wxconf/applet/applet";
    bootbox.dialog({
        message: "确定要删除",
        title: "提示",
        buttons: {
            cancel: {
                label: "取消",
                className: "btn dark btn-outline"
            },
            success: {
                label: "确定",
                className: "btn green",
                callback: function() {
                    // alert('提交删除');
                    var _data = JSON.stringify({ id: _id });
                    request_role_del(_data, function(res) {
                        // 正确
                    	window.location.reload();
                    }, function(err) {
                        //	错误
                        alert(err);
                    })
                }
            }
        }
    });
}



/*
页面加载完毕 发起请求获取七牛token，通过前台传到七牛
*/
function getQinniuTokenMessage(pickfiles) {
	var qiniupercent="";
	$.ajax({
		url: '/a/qiniu/uptoken',
		type: 'POST',
		data: {},
		cache: false,
		contentType: false,    //不可缺
		processData: false,    //不可缺
		dataType : 'json',
		success: function (data) {
			var obj = data;
			uploaderQiniuReady(obj.uptoken,qiniupercent,pickfiles);
		  }
		});
}


function getVideoTokenMessage(pickfiles) {
	var qiniupercent="";
	$.ajax({
		url: '/a/qiniu/uptoken',
		type: 'POST',
		data: {},
		cache: false,
		contentType: false,    //不可缺
		processData: false,    //不可缺
		dataType : 'json',
		success: function (data) {
			var obj = data;
			mdTool.uploaderVideoReady(obj.uptoken,qiniupercent,pickfiles);
		  }
		});
}


/*
页面加载完毕 发起请求获取七牛token，通过前台传到七牛
*/
function getTokenMessage() {
	var url="";
	var qiniupercent="";
	var uploader="btn-uploader";
	var pickfiles="pickfiles";
	$.ajax({
		url: '/a/qiniu/uptoken',
		type: 'POST',
		data: {},
		cache: false,
		contentType: false,    //不可缺
		processData: false,    //不可缺
		dataType : 'json',
		success: function (data) {
			var obj = data;
			uploaderReady(obj.uptoken,url,qiniupercent,uploader,pickfiles);
		  }
		});
}

function getTokenMessage1(pickfiles) {
    var url="";
    var uploader="btn-uploader";
    var qiniupercent="";
    $.ajax({
        url: '/a/qiniu/uptoken',
        type: 'POST',
        data: {},
        cache: false,
        contentType: false,    //不可缺
        processData: false,    //不可缺
        dataType : 'json',
        success: function (data) {
            var obj = data;
            mdTool.uploaderReady(obj.uptoken,url,qiniupercent,uploader,pickfiles,'500KB',"jpg,jpeg,gif,png");

        }
    });
};


/*轮播设置按钮js*/
$(".banner .btn_edit_role").click(function(){
	console.log("轮播设置");
	var frameId=$(this).prev().val();
	var param={"frameId":frameId};
    $('#advertisement_talbe').DataTable().search(JSON.stringify(param)  ).draw();
  	$(".ban-site").show().siblings(".site").hide();
  	$("#applet .btn_cancle_role").parent().parent().remove();
  	$(".site .btn-success").attr("disabled",false);
  	$("#frameIds").val(frameId);
  	$(' .help-block').html('');
  	$('body,html').animate({scrollTop:0},300);
  	
  });
/*按钮设置js*/
  $(".btn-nav .btn_edit_role").click(function(){
  	console.log("按钮设置");
	var frameId=$(this).prev().val();
	var  _data= getFrameInfo(frameId)
	var backgroud=_data.backgroud;
	var displayType=_data.displayType;
	 var param={"frameId":frameId};
      $('#iconArea_talbe').DataTable().search(JSON.stringify(param)  ).draw();
  	$(".btn-nav-site").show().siblings(".site").hide();
  	$("#applet .btn_cancle_role").parent().parent().remove();
  	$(".site .btn-success").attr("disabled",false);
  	$("#frameIds").val(frameId);
  	$(' .help-block').html('');
  	 $('#square1').css("background-color",backgroud);
  	$("input[name='displayType'][value='"+displayType+"']").prop("checked",true); 

  	$('body,html').animate({scrollTop:0},300);
  	
  });
  /*商品设置*/
  $(".recom-pro .btn_edit_role").click(function(){
  	console.log("3");
	  var frameId=$(this).prev().val();
	  var  _data= getFrameInfo(frameId)
	  var backgroud=_data.backgroud;
	  var displayType=_data.displayType;
	  var titleType=_data.titleType;
	  var name=_data.name;
	  var param={"frameId":frameId};
	  $('#commodity_table').DataTable().search(JSON.stringify(param)  ).draw();
  	$(".btn-pro-site").show().siblings(".site").hide();
  	$("#applet .btn_cancle_role").parent().parent().remove();
  	$(".site .btn-success").attr("disabled",false);
  	$("#frameIds").val(frameId);
  	$(' .help-block').html('');
  	$('body,html').animate({scrollTop:0},300);
 	 $('#square2').css("background-color",backgroud);
   	$(".btn-pro-site input[name='displayType'][value='"+displayType+"']").prop("checked",true); 

 	 if(titleType){
   	$(".btn-pro-site input[name='titleType'][value='"+titleType+"']").prop("checked",true); 
 	 }else{
 	   	$(".btn-pro-site input[name='titleType'][value='文字标题']").prop("checked",true); 

 	 }
   	if(titleType=='图片标题'){
   		$(".btn-pro-site .text_title").hide();
		$(".btn-pro-site .pic_title").show();
        $('#pickfiles1 [name="img_qiniu_url"]').attr('src',name); 
        
		 // getTokenMessage();
   	}else{
   		$(".btn-pro-site .text_title").show();
		$(".btn-pro-site .pic_title").hide();
		$('#frameName').val(name);
   	}

  });
  
  
  /*拼团设置*/
  $(".pintuan-group .btn_edit_role").click(function(){
  	console.log("拼团设置");
	  var frameId=$(this).prev().val();
	  var  _data= getFrameInfo(frameId)
	  var name=_data.name;
	  var backgroud=_data.backgroud;
	  var titleType=_data.titleType;
	  var param={"frameId":frameId};
	  $('#groupbuy_table').DataTable().search(JSON.stringify(param)  ).draw();
  	$(".btn-groupbuy-site").show().siblings(".site").hide();
  	$("#applet .btn_cancle_role").parent().parent().remove();
  	$(".site .btn-success").attr("disabled",false);
  	$("#frameIds").val(frameId);
  	$(' .help-block').html('');
  	$('body,html').animate({scrollTop:0},300);
 	 $('#square4').css("background-color",backgroud);
 	 if(titleType){
   	$(".btn-groupbuy-site input[name='titleType'][value='"+titleType+"']").prop("checked",true); 
 	 }else{
  	   	$(".btn-groupbuy-site input[name='titleType'][value='文字标题']").prop("checked",true); 

 	 }
   	if(titleType=='图片标题'){
   		$(".btn-groupbuy-site .text_title").hide();
		$(".btn-groupbuy-site .pic_title").show();
        $('#pickfiles3 [name="img_qiniu_url"]').attr('src',name); 
		 // getTokenMessage();
   	}else{
   		$(".btn-groupbuy-site .text_title").show();
		$(".btn-groupbuy-site .pic_title").hide();
		$('#frameName1').val(name);
   	}
  
  });
  
  
  
  
  
  /*文章设置*/
  $(".recom-article .btn_edit_role").click(function(){
  	console.log("文章设置");
	  var frameId=$(this).prev().val();
	  var  _data= getFrameInfo(frameId)
	  var backgroud=_data.backgroud;
	  var name=_data.name;
	  var titleType=_data.titleType;
	  var displayType=_data.displayType;
	  var param={"frameId":frameId};
      $('#article_ban_table').DataTable().search(JSON.stringify(param)  ).draw();
	var siteClass="btn-article-site";
  	$("."+siteClass).show().siblings(".site").hide();
  	$("#applet .btn_cancle_role").parent().parent().remove();
  	$(".site .btn-success").attr("disabled",false);
  	$("#frameIds").val(frameId);
  	$(' .help-block').html('');
  	$('body,html').animate({scrollTop:0},300);
 	 $("#square7").css("background-color",backgroud);
 	 if(titleType){
   	$("."+siteClass+" input[name='titleType'][value='"+titleType+"']").prop("checked",true); 
 	 }else{
  	   	$("."+siteClass+" input[name='titleType'][value='文字标题']").prop("checked",true); 

 	 }
   	$("input[name='displayType'][value='"+displayType+"']").prop("checked",true); 

   	if(titleType=='图片标题'){
   		$(".text_title").hide();
		$(".pic_title").show();
        $('#pickfiles8 [name="img_qiniu_url"]').attr('src',name); 
   	}else{
   		$(" .text_title").show();
		$(".pic_title").hide();
		$("."+siteClass+" input[name='frameName']").val(name);
   	}
  });
    /*视频设置*/
    $(".recom-video .btn_edit_role").click(function(){
    	console.log("视频设置");
		  var frameId=$(this).prev().val();
		  var  _data= getFrameInfo(frameId)
		  var backgroud=_data.backgroud;
		  var displayType=_data.displayType;
		  var titleType=_data.titleType;
		  var name=_data.name;
		  var imgUrl=_data.createOper;
		  var videoUrl=_data.updateOper;
  		var siteClass="btn-video-site";
    	$("."+siteClass).show().siblings(".site").hide();
    	$("#applet .btn_cancle_role").parent().parent().remove();
    	$(".site .btn-success").attr("disabled",false);
    	$("#frameIds").val(frameId);
    	$(' .help-block').html('');
    	$('body,html').animate({scrollTop:0},300);
   	 $('#square5').css("background-color",backgroud);
   	 if(imgUrl.indexOf('/p/wxconf')>-1){
   		imgUrl="";
	     }
   	 if(imgUrl)
   	 $('#pickfiles6 [name="img_qiniu_url"]').attr('src',imgUrl); 
   	 $('#pickfiles7 [name="img_qiniu_url"]').attr('src',videoUrl); 
   	 if(titleType){
     	$("."+siteClass+" .site_titleType[value='"+titleType+"']").prop("checked",true); 
   	 }else{
    	   	$("."+siteClass+" site_titleType[value='文字标题']").prop("checked",true); 
   	 }

     	if(titleType=='图片标题'){
     	$(".text_title").hide();
  		$(".pic_title").show();
          $('#pickfiles5 [name="img_qiniu_url"]').attr('src',name); 
     	}else{
     		$(" .text_title").show();
  		$(".pic_title").hide();
  		$('.site_frameName').val(name);
     	}

    
    });
   	
  
    
    /*图片自适应*/
    $(".recom-pic .icon-settings").click(function(){
    	console.log("文章设置");
  	  var frameId=$(this).prev().val();
  	  var  _data= getFrameInfo(frameId)
  	  var backgroud=_data.backgroud;
  	  var name=_data.name;
  	  var titleType=_data.titleType;
  	  var displayType=_data.displayType;
  	  var param={"frameId":frameId};
        $('#pic_ban_table').DataTable().search(JSON.stringify(param)  ).draw();
  	var siteClass="btn-pic-site";
    	$("."+siteClass).show().siblings(".site").hide();
    	$("#applet .btn_cancle_role").parent().parent().remove();
    	$(".site .btn-success").attr("disabled",false);
    	$("#frameIds").val(frameId);
    	$(' .help-block').html('');
    	$('body,html').animate({scrollTop:0},300);
   	 $("#square8").css("background-color",backgroud);
   	 if(titleType){
     	$("."+siteClass+" input[name='titleType'][value='"+titleType+"']").prop("checked",true); 
   	 }else{
    	   	$("."+siteClass+" input[name='titleType'][value='文字标题']").prop("checked",true); 

   	 }
     	$("input[name='displayType'][value='"+displayType+"']").prop("checked",true); 

     	if(titleType=='图片标题'){
     		$(".text_title").hide();
  		$(".pic_title").show();
          $('#pickfiles9 [name="img_qiniu_url"]').attr('src',name); 
     	}else{
     		$(" .text_title").show();
  		$(".pic_title").hide();
  		$("."+siteClass+" input[name='frameName']").val(name);
     	}
    });
    

  
/*通过id获取抬头信息
 * **/
  function getFrameInfo(_id){
	  var _data;
		$.ajax({
			url : '/a/wxconf/applet/wxFrameConf?id='+ encodeURIComponent(_id),
			type : 'GET',
			dataType : 'json',
			async: false,
			contentType:"application/json; charset=utf-8",
//			data : JSON.stringify(id),
		}).done(function(data) {
			if (data.status === '1') {
				_data=data.data
			} else if (data.status === '2') {
			}
		});
		return _data;
	  	
}
  
  
  $(".btn-add-ban").click(function(){
  	var param={"name":"轮播广告","type":"1","displayType":"1"};
  	ajaxReq(param)
	  });
  
  $(".btn-add-nav").click(function(){
	  	var param={"name":"图标按钮","type":"2","displayType":"3"};
	  	ajaxReq(param)
		  });
  
  $(".btn-add-pro").click(function(){
	  	var param={"name":"推荐商品","type":"3","displayType":"2","titleType":"文字标题"};
	  	ajaxReq(param)
		  });
  $(".btn-add-pic").click(function(){
	  	var param={"name":"自适应图片","type":"8","displayType":"1","titleType":"文字标题"};
	  	ajaxReq(param)
		  });
  $(".btn-add-line").click(function(){
	  	var param={"name":"华丽分割线","type":"4","displayType":"1"};
	  	ajaxReq(param);
		  });
/*  $(".btn-add-pic").click(function(){
	  	var param={"name":"橱窗","type":"5","displayType":"1"};
	  	ajaxReq(param);
		  });*/
  $(".btn-add-group").click(function(){
	  	var param={"name":"拼团","type":"6","displayType":"1","titleType":"文字标题"};
	  	ajaxReq(param);
		  });
  
  $(".btn-add-article").click(function(){
	  	var param={"name":"文章板块","type":"7","displayType":"1","titleType":"文字标题"};
	  	ajaxReq(param);
		  });	
  
  $(".btn-add-video").click(function(){
	  	var param={"name":"视频","type":"5","displayType":"1","titleType":"文字标题"};
	  	ajaxReq(param);
		  });	
	  
  function ajaxReq(param){
		$.ajax({
			url : '/a/wxconf/applet/wxFrameConf',
			type : 'PUT',
			dataType : 'json',
			contentType:"application/json; charset=utf-8",
			data : JSON.stringify(param),
		}).done(function(data) {
			if (data.status === '1') {
				// 正确
				window.location.reload();
			} else if (data.status === '2') {
//				错误
//				mdTool.showMessageForHelpBlock(data.message);
			}
		});
	  	
  }
  
  

  
/*标题选择切换*/
$(".btn-pro-site input[name='titleType']").change(function(){
	if ($("input[name='titleType']:checked").val() == "文字标题") {
		$(".btn-pro-site .text_title").show();
		$(".btn-pro-site .pic_title").hide();
	}else{
		$(".btn-pro-site .text_title").hide();
		$(".btn-pro-site .pic_title").show();
		//  getTokenMessage();
	}
});
$(".btn-spike-site input[name='title2']").change(function(){
	if ($("input[name='title2']:checked").val() == "文字标题") {
		$(".btn-spike-site .text_title").show();
		$(".btn-spike-site .pic_title").hide();
	}else{
		$(".btn-spike-site .text_title").hide();
		$(".btn-spike-site .pic_title").show();
	}
});
$(".btn-groupbuy-site input[name='titleType']").change(function(){
	if ($("input[name='titleType']:checked").val() == "文字标题") {
		$(".btn-groupbuy-site .text_title").show();
		$(".btn-groupbuy-site .pic_title").hide();
	}else{
		$(".btn-groupbuy-site .text_title").hide();
		$(".btn-groupbuy-site .pic_title").show();
	}
});
$(".btn-article-site input[name='titleType']").change(function(){
	if ($("input[name='titleType']:checked").val() == "文字标题") {
		$(".btn-article-site .text_title").show();
		$(".btn-article-site .pic_title").hide();
	}else{
		$(".btn-article-site .text_title").hide();
		$(".btn-article-site .pic_title").show();
	}
});

$(".btn-video-site input[name='titleType']").change(function(){
	if ($("input[name='titleType']:checked").val() == "文字标题") {
		$(".btn-video-site .text_title").show();
		$(".btn-video-site .pic_title").hide();
	}else{
		$(".btn-video-site .text_title").hide();
		$(".btn-video-site .pic_title").show();
	}
});

$(".btn-pic-site input[name='titleType']").change(function(){
	if ($("input[name='titleType']:checked").val() == "文字标题") {
		$(".btn-pic-site .text_title").show();
		$(".btn-pic-site .pic_title").hide();
	}else{
		$(".btn-pic-site .text_title").hide();
		$(".btn-pic-site .pic_title").show();
	}
});

/*拖动*/
var listcount = $(".con_mainList").parent("div").length;
//console.log(listcount);
for (var c=0;c<listcount;c++) {
	$(".con_mainList").eq(c).parent("div").attr("id","list"+c);
}

var arr = '';
var sort = $(".sortable").sortable({
	handle: ".glyphicon-move",
	opacity: 0.7,
	delay: 150,
	cursor: 'move',
	revert: true,
	stop: function() {
		//记录sort后的id顺序数组
		var arr = $(".sortable").sortable('toArray');
		
		console.log(arr);
		var param=new Array(arr.length);
		for(var i=0;i<arr.length;i++){
			 var did= arr[i];
			 var frameId=$('#'+did+" input[name='frameId']" ).val();
//			 param[i]="{'id':"+frameId+",'orderNo':"+(i+1)+"}";
			 param[i]={"id":frameId,"orderNo":i+1};
			 console.log(frameId);
			}
		$.ajax({
			url : '/a/wxconf/applet/move',
			type : 'POST',
			dataType : 'json',
			contentType:"application/json; charset=utf-8",
			data : JSON.stringify(param),
		}).done(function(data) {
			if (data.status === '1') {
				// 正确
				window.location.reload();
			} else if (data.status === '2') {
//				错误
//				mdTool.showMessageForHelpBlock(data.message);
			}
		});
		//拖拽后利用localStorage记录顺序
		localStorage.arr = arr;
	}
});
var localSt = localStorage.arr;
//如果有localst记录则，按照这个进行排序元素
/*if(localSt) {
	var resArr = localSt.split(',');
	var resUl = $('.sortable');
	//li 数组
	for(var i = 0; i < resArr.length; i++) {
		resUl.append($("#" + resArr[i]));
	}
}*/




$("#applet .con_mainList").hover(function(){
	$(this).find(".btn-group").show();
},function(){
	$(this).find(".btn-group").hide();
});


/*----------2.2版本添加js-----------*/

// 按钮导航确认按钮
$('.iconArea_sure').on('click', function(event) {
  var color= $('#square1').css("background-color");
	var frameId=$("#frameIds").val();
	var displayType=$("#iconAreaList input[name='displayType']:checked").val();
	var param={"id":frameId,"displayType":displayType,"backgroud":color};
	var msgId="iconAreaList .help-block";
	ajaxFrameReq(param,msgId);
});



// 推荐商品确认按钮
$('#updateName_btn').on('click', function(event) {
	var frameName= $('#frameName').val(); 
	var frameId=$("#frameIds").val();
	var color= $('#square2').css("background-color");
	var titleType =$(".btn-pro-site input[name='titleType']:checked").val(); 
/*    var imgUrl= $('#advertisement [name="img_qiniu_url"]')[0].src; 
*/
	var displayType=$("#commoditylist input[name='displayType']:checked").val();

	if(titleType=='图片标题'){
		frameName= $('#pickfiles1 [name="img_qiniu_url"]')[0].src; 
		     if(frameName.indexOf(window.location.pathname)>-1){
		    	 frameName="";
		     }
		     if (!mdTool.validate(frameName, 'require')) {
		    	 mdTool.showMessageForHelpBlock('请选择图片标题');
			 		return;
		 	}
		    
	}
	var param={"id":frameId,"name":frameName,"backgroud":color,"titleType":titleType,"displayType":displayType};
	var msgId=" .help-block";
	if (!mdTool.validate(titleType, 'require')) {
		mdTool.showMessageForHelpBlock('请选择模块标题');
		return;
	}
	
   else {
	   ajaxFrameReq(param,msgId);
	}
});



//拼团确认按钮
$('#updateName_btn1').on('click', function(event) {
	var frameName= $('#frameName1').val(); 
	var frameId=$("#frameIds").val();
	var color= $('#square4').css("background-color");
	var titleType =$("input[name='titleType']:checked").val(); 
/*    var imgUrl= $('#advertisement [name="img_qiniu_url"]')[0].src; 
*/
	if(titleType=='图片标题'){
		frameName= $('#pickfiles3 [name="img_qiniu_url"]')[0].src; 
		     if(frameName.indexOf(window.location.pathname)>-1){
		    	 frameName="";
		     }
		     if (!mdTool.validate(frameName, 'require')) {
		    	 mdTool.showMessageForHelpBlock('请选择图片标题');
			 		return;
		 	}
		    
	}
	var param={"id":frameId,"name":frameName,"backgroud":color,"titleType":titleType};
	var msgId=" .help-block";
	if (!mdTool.validate(titleType, 'require')) {
		mdTool.showMessageForHelpBlock('请选择模块标题');
		return;
	}
else {
	   ajaxFrameReq(param,msgId);
	}
});

//文章确认按钮
$('#article_sure_btn').on('click', function(event) {
	var frameName= $(".btn-article-site input[name='frameName']").val(); 
	var frameId=$("#frameIds").val();
	var color= $('#square7').css("background-color");
	var titleType =$(".btn-article-site input[name='titleType']:checked").val(); 

	var displayType=$(".btn-article-site input[name='displayType']:checked").val();

	if(titleType=='图片标题'){
		frameName= $('#pickfiles8 [name="img_qiniu_url"]')[0].src; 
		     if(frameName.indexOf(window.location.pathname)>-1){
		    	 frameName="";
		     }
		     if (!mdTool.validate(frameName, 'require')) {
		    	 mdTool.showMessageForHelpBlock('请选择图片标题');
			 		return;
		 	}
		    
	}
	var param={"id":frameId,"name":frameName,"backgroud":color,"titleType":titleType,"displayType":displayType};
	var msgId=" .help-block";
	if (!mdTool.validate(titleType, 'require')) {
		mdTool.showMessageForHelpBlock('请选择模块标题');
		return;
	}
   else {
	   ajaxFrameReq(param,msgId);
	}
});


//自适应确认按钮
$('#pic_sure_btn').on('click', function(event) {
	var frameName= $(".btn-pic-site input[name='frameName']").val(); 
	var frameId=$("#frameIds").val();
	var color= $('#square8').css("background-color");
	var titleType =$(".btn-pic-site input[name='titleType']:checked").val(); 

	var displayType=$(".btn-pic-site input[name='displayType']:checked").val();

	if(titleType=='图片标题'){
		frameName= $('#pickfiles9 [name="img_qiniu_url"]')[0].src; 
		     if(frameName.indexOf(window.location.pathname)>-1){
		    	 frameName="";
		     }
		     if (!mdTool.validate(frameName, 'require')) {
		    	 mdTool.showMessageForHelpBlock('请选择图片标题');
			 		return;
		 	}
		    
	}
	var param={"id":frameId,"name":frameName,"backgroud":color,"titleType":titleType,"displayType":displayType};
	var msgId=" .help-block";
	if (!mdTool.validate(titleType, 'require')) {
		mdTool.showMessageForHelpBlock('请选择模块标题');
		return;
	}

   else {
	   ajaxFrameReq(param,msgId);
	}
});

//视频确认按钮
$('#video_sure_btn').on('click', function(event) {
	var frameName= $(".btn-video-site .site_frameName").val(); 
	var frameId=$("#frameIds").val();
	var color= $('#square5').css("background-color");
	var titleType =$(".btn-video-site input[name='titleType']:checked").val(); 

	var displayType=$(".btn-video-site input[name='displayType']:checked").val();

	if(titleType=='图片标题'){
		frameName= $('#pickfiles5 [name="img_qiniu_url"]')[0].src; 
		     if(frameName.indexOf(window.location.pathname)>-1){
		    	 frameName="";
		     }
		     if (!mdTool.validate(frameName, 'require')) {
		    	 mdTool.showMessageForHelpBlock('请选择图片标题');
			 		return;
		 	}
		    
	}
	var imgUrl= $('#pickfiles6 [name="img_qiniu_url"]')[0].src; 
	var videoUrl= $('#pickfiles7 [name="img_qiniu_url"]')[0].src; 


	var msgId=" .help-block";
	if (!mdTool.validate(titleType, 'require')) {
		mdTool.showMessageForHelpBlock('请选择模块标题');
		return;
	}
	  if(videoUrl.indexOf('/p/wxconf')>-1){
		  videoUrl="";
	     }
	if (!mdTool.validate(videoUrl, 'require')) {
		mdTool.showMessageForHelpBlock('请上传视频');
		return;
	}

	else {
		var param={"frame":{"id":frameId,"name":frameName,"backgroud":color,"titleType":titleType,"displayType":"1"},
				"WxComponentConf":{"frameId":frameId,"orderNo":"1","displayName":"视频","imgUrl":imgUrl,"videoUrl":videoUrl
				}};

		ajaxFrameReqVideo(param);
		}
});


function ajaxFrameReq(param,msgId){
	$.ajax({
		url : '/a/wxconf/applet/wxFrameConf',
		type : 'POST',
		dataType : 'json',
		contentType:"application/json; charset=utf-8",
		data : JSON.stringify(param),
	}).done(function(data) {
		if (data.status === '1') {
			// 正确
			window.location.reload();


		} else if (data.status === '2') {
//			错误
			mdTool.showMessageForHelpBlock(data.message);
		}
	});
  	
}

function ajaxFrameReqVideo(param){
	$.ajax({
		url : '/a/wxconf/applet/wxFrameConfVideo',
		type : 'POST',
		dataType : 'json',
		contentType:"application/json; charset=utf-8",
		data : JSON.stringify(param),
	}).done(function(data) {
		if (data.status === '1') {
			// 正确
			window.location.reload();


		} else if (data.status === '2') {
//			错误
			mdTool.showMessageForHelpBlock(data.message);
		}
	});
  	
}

$(".styleCon-settings").on("click",function(){
	$("#ban-pic").modal("show");

});


var myVideo=document.getElementById("video1");  
function playPause(){   
    if (myVideo.paused)   
        myVideo.play();   
    else   
        myVideo.pause();   
}   
function makeBig(){   
    myVideo.width=560;   
}   
function makeSmall(){   
    myVideo.width=320;   
}   
function makeNormal(){   
    myVideo.width=420;   
}   

$(function() {
	getTokenMessage();
    roleManage.init();
    $(".banner .item:first-child").addClass("active");
    
    $('.square').colpick({
		colorScheme:'dark',
		layout:'rgbhex',
		color:'ffffff',
		livePreview:0,
		onSubmit:function(hsb,hex,rgb,el) {
			$(el).css('background-color', '#'+hex);
			$(el).colpickHide();
		}
	})
	.css('background-color', '#ffffff');
    
    
    
    $(".stylelist ul li:first-child input[type='radio']").attr("checked","checked");
    $(".styleCon .pic_con").eq(0).show();
    $(".stylelist ul li").click(function(){
		var n = $(this).index();
		$(".styleCon .pic_con").eq(n).show().siblings().hide();
	});

	getQinniuTokenMessage("pickfiles1");
	getQinniuTokenMessage("pickfiles8");
	getQinniuTokenMessage("pickfiles3");
	getQinniuTokenMessage("pickfiles5");
	getQinniuTokenMessage("pickfiles6");
	getVideoTokenMessage("pickfiles7");
    getTokenMessage1("pickfiles9");



	
	var $divWidth = $('#iconArea img').width();
    $('#iconArea img').css({'height':$divWidth});
});

